{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('A', 'a'), ('B', 'b'), ('C', 'c'), ('D', 'd'), ('E', 'e'), ('F', 'f'), ('G', 'g'), ('H', 'h'), ('I', 'i'), ('J', 'j'), ('K', 'k'), ('L', 'l'), ('M', 'm'), ('N', 'n'), ('O', 'o'), ('P', 'p'), ('Q', 'q'), ('R', 'r'), ('S', 's'), ('T', 't'), ('U', 'u'), ('V', 'v'), ('W', 'w'), ('X', 'x'), ('Y', 'y'), ('Z', 'z')]\n",
      "A - a\n",
      "B - b\n",
      "C - c\n",
      "D - d\n",
      "E - e\n",
      "F - f\n",
      "G - g\n",
      "H - h\n",
      "I - i\n",
      "J - j\n",
      "K - k\n",
      "L - l\n",
      "M - m\n",
      "N - n\n",
      "O - o\n",
      "P - p\n",
      "Q - q\n",
      "R - r\n",
      "S - s\n",
      "T - t\n",
      "U - u\n",
      "V - v\n",
      "W - w\n",
      "X - x\n",
      "Y - y\n",
      "Z - z\n"
     ]
    }
   ],
   "source": [
    "#1.将所有大小写英文字母的字符以成对的形式放到一个数组中，要求每对是一个元组，比如[('A','a'),('B','b'),...]；\n",
    " # A - aB - b\n",
    "import string\n",
    "#help(string)\n",
    "a = string.ascii_lowercase\n",
    "b = string.ascii_uppercase\n",
    "d = []\n",
    "for i in range(len(a)):\n",
    "    c = (b[i],a[i])\n",
    "    d.append(c)\n",
    "print(d)\n",
    "for i in range(len(d)):\n",
    "    print(d[i][0],\"-\",d[i][1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
     ]
    }
   ],
   "source": [
    "#1.在当前工作文件夹下创建50个以test为前缀，不重名的文件夹。\n",
    "#2.统计一个文件个数超过20的文件夹中（比如C:\\Windows\\System32），不同类型（后缀）文件的个数，并打印出来(选做)。\n",
    "import os\n",
    "path = r'D:\\电子知识库\\vescode\\python2.0\\上课-test' \n",
    "a = \"test\" \n",
    "b = list(i for i in range(50))\n",
    "print(b[:10])\n",
    "for j in range(len(b)):\n",
    "\n",
    "    os.mkdir(path + './'+a+str(b[j]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                         1*1=1  \n",
      "                      2*1=2 2*2=4  \n",
      "                   3*1=3 3*2=6 3*3=9  \n",
      "                4*1=4 4*2=8 4*3=12 4*4=16  \n",
      "             5*1=5 5*2=10 5*3=15 5*4=20 5*5=25  \n",
      "          6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36  \n",
      "       7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49  \n",
      "    8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64  \n",
      " 9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81  \n"
     ]
    }
   ],
   "source": [
    "#以金字塔方式打印九九乘法表\n",
    "for i in range(1,10):\n",
    "    for j in range(1,i+1):\n",
    "        if j==1:\n",
    "            print(\"   \"*(9-i),f\"{i}*{1}={i}\",end=\" \")\n",
    "        else:\n",
    "            print(f'{i}*{j}={i*j}',end=\" \")\n",
    "    print(\" \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'list'>\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for +: 'int' and 'list'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-18-cbd11399ae7f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     18\u001b[0m     \u001b[0mm\u001b[0m\u001b[1;33m==\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     19\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 20\u001b[1;33m \u001b[0mw\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0md\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m2\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mm\u001b[0m\u001b[1;33m+\u001b[0m \u001b[1;36m3\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m//\u001b[0m \u001b[1;36m5\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m//\u001b[0m \u001b[1;36m4\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m//\u001b[0m \u001b[1;36m100\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m//\u001b[0m\u001b[1;36m400\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m%\u001b[0m \u001b[1;36m7\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     21\u001b[0m \u001b[1;31m# 计算1，2月时，需要当作上一年的13、14月使用\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     22\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mget_which_week\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0md\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'list'"
     ]
    }
   ],
   "source": [
    "#生成并打印2021年的日历，要求以类似如下格式打印：\n",
    "def how_many_days_month(y,m):\n",
    "   '''计算这一月的天数，按顺序传入年月日'''\n",
    "   # 闰年判定方法：能被400整除。或者能被4整除但不能被100整除。\n",
    "   if m in [1,3,5,7,8,10,12]:\n",
    "       days = 31\n",
    "   elif m in [4,6,9,11]:\n",
    "       days = 30\n",
    "   elif m == 2:\n",
    "       if y//400 == 0 or (y // 4 and y // 100 != 0):\n",
    "           days = 29\n",
    "       else:\n",
    "           days = 28\n",
    "   return days\n",
    "y = 2021\n",
    "m0 = list(range(1,13))\n",
    "for i in m0:\n",
    "    m==i\n",
    "print(type(m))\n",
    "w = (d + 2 * m+ 3 * (m + 1)// 5 + y + y // 4 - y // 100 + y //400) % 7 +1\n",
    "# 计算1，2月时，需要当作上一年的13、14月使用\n",
    "def get_which_week(y,m,d):\n",
    "   '''计算星期几的函数，按顺序传入年月日'''\n",
    "   if m == 1: # w所在的行为计算公式，但如果是1，2月，则需要将其作为前一年的13、14月来计算\n",
    "       y = y - 1\n",
    "       m = 13\n",
    "   elif m == 2:\n",
    "       y = y - 1\n",
    "       m = 14\n",
    "   w = (d + 2 * m+ 3 * (m + 1)// 5 + y + y // 4 - y // 100 + y // 400) % 7 +1\n",
    "   return w\n",
    "def input_yms():\n",
    "   '''提示用户输入年月日,无需传入参数，返回一个年月日数值为元素的元组'''\n",
    "   inputstr = ('year','month','day')\n",
    "   y = int(input('Please input the number of {[0]}:'.format(inputstr)))\n",
    "   m = int(input('Please input the number of {[1]}:'.format(inputstr)))\n",
    "   d = int(input('Please input the number of {[2]}:'.format(inputstr)))\n",
    "   return y,m,d\n",
    "   y,m,d = input_yms()\n",
    "days = how_many_days_month(y,m)\n",
    "for i in range(12):\n",
    "\n",
    "    print(f'\\n{y}年{m}月 格里高利历')\n",
    "    print('一 二 三 四 五 六 日')\n",
    "    print('-'*20)\n",
    "    for i in range(1,days+1):\n",
    "        w = get_which_week(y,m,i)\n",
    "        if i == 1:\n",
    "            print(f\"{' '*(w-1)*3}\",end = '')\n",
    "        else:\n",
    "            if w == 1:\n",
    "               print('')\n",
    "        print(f\"{i:2d}\", end = ' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "a4c6f6dca0b39727a1d31abc575f26c9e9c5e97275968b776bf7d6bafbe246da"
  },
  "kernelspec": {
   "display_name": "Python 3.8.8 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
